<#import "/macro/pmmacro.ftl" as pmmacro >
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${basepath}/css/pm.css" type="text/css">
<style type="text/css">
body{
	padding:0px;
	margin:0px;
}
#divresult table{
	width: 99%;
	margin-top:20px;
}
#divresult table th,td{
	border: 1px solid #cccccc;
	font-size: 14px;
	font-family: serif;
	text-align :left;
}
</style>
</head>

<body>

<div id="divresult" style="min-height:500px;">
<div>
<table id="duser_table" cellpadding="0" cellspacing="0">
	<thead>
		<tr>
			<td>昵称</td>
			<td>登录账号</td>
			<td>是否在线</td>
			<td>状态</td>
			<td>操作</td>
			
		</tr>
	</thead>
	<tbody id="duser_tbody">
		<#list pager.result as user>
			<tr>
				<td>${(user.nickName?html)!""}</td>
				<td>${(user.userName?html)!""}</td>
				<td>
					<#if SessionStorer.fetch(user.pmdept.id,user.id)??>
						在线${SESSION_LAST_REQUEST_TIME}
					<#else>
						离线
					</#if>
				</td>
				<td>
					<input value="启用" type="button" <#if user.status == 1>disabled="disabled"</#if> <#if !user.isAdmin > onclick="javascript: enableduser('${user.id}');" </#if>/>	
					<#if SESSION_CURRENT_USER.isAdmin >
						<#if !user.isAdmin >			
							<input value="禁用" type="button" <#if user.status == 0>disabled="disabled"</#if> <#if !user.isAdmin >onclick="javascript: disableduser('${user.id}');" </#if>/>
						</#if>
					</#if>							
				</td>
				<td>
					<a href="javascript: viewuserinfo(${user.id});" >查看/修改</a>
					<#-- &nbsp;<a href="javascript:;" onclick="javascript: userform.removeuser('${user.id}');">删除</a> -->
					<#if SESSION_CURRENT_USER.isAdmin >
						<#if !user.isAdmin >
							&nbsp;<a href="javascript: distributionUserPower(${user.id});" >分配权限</a>
						</#if>
							&nbsp;<a href="javascript: resetUserPasswd(${user.id});" >重置密码</a>
					</#if>
					
				</td>
			</tr>
		</#list>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="5">
				<@pmmacro.pagetool url="${basepath}/user/page"/>
			</td>
		</tr>
	</tfoot>
</table>
</div>

<div id="reset_passwd_div" style="display:none;">
	<form method="post" target="_parent" id="resetform" name="resetform" action="${basepath}/user/passwd/reset.htm" >
	<fieldset id="order_field">
		<ul id="reset_passwd_ul">
			<li><label>重置密码:<input type="password"
					id="passwd" onblur="javascript: passvalid();"/>
					<input type="hidden" name="passwd" id="passwd_md5" />
			</label>
				<div id="passwdTip"></div></li>
			<li><label>确认密码:<input type="password" 
					id="passwd2" onblur="javascript: pass2valid();"/>
			</label>
				<div id="passwd2Tip"></div></li>
		</ul>
	</fieldset>
	<p>
	<input type="hidden" name="_method" value="put"/> 
	<input type="hidden" name="userId" id="resetPasswdUserId" />
	</p>
	</form>
</div>
</div>
</body>
<script type="text/javascript" src="${basepath}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${basepath}/js/common_szy.js"></script>
<script type="text/javascript" src="${basepath}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
(function(){
	window.parent.document.getElementById("resultpage").scrolling='no';
})();
<#--激活用户-->
function enableduser(userId){
	getpostform("${basepath}/user/enable.htm","post","_parent",{"_method":"put","userId":userId});
};
<#--禁用用户-->
function disableduser(userId){
	getpostform("${basepath}/user/disable.htm","post","_parent",{"_method":"put","userId":userId});
};
<#--分配权限-->
function distributionUserPower(userId){
	$.get("${basepath}/power/user/distribution.htm",{
		"userId":userId
	},function(data){
		$.dialog({
			title : "修改员工权限",
			content: data,
			max : false,
			min : false,
			resize : false,
			ok : function(){
				$("#distributionuserpowerform").submit();
				return true;
			},
			cancelVal : '取消',
			cancel : true
		});
	});
};
<#--重置密码-->
function resetUserPasswd(userId){
	var data = $("#reset_passwd_div").html();
	$.dialog({
		title : "重置员工密码",
		content: data,
		max : false,
		min : false,
		resize : false,
		ok : function(){
			$("#resetPasswdUserId").attr("value",userId);
			$("#passwd_md5").attr("value",$("#passwd").attr("value"));
			$("#resetform").submit();
			return true;
		},
		cancelVal : '取消',
		cancel : true
	});
};
<#--查看用户详情-->
function viewuserinfo(userId){
	$.get("${basepath}/user/info.htm",{"userId":userId},function(data){
		$.dialog({
			title : "用户信息",
			content: data,
			max : false,
			min : false,
			resize : false,
			ok : function(){
				return true;
			},
			cancelVal : '关闭',
			cancel : true
		});
	});
}

function passvalid(){
	if($("#passwd").attr("value").length < 1){
		$("#passwdTip").html("<span style='color:red;'>重置密码不能为空!</span>");
		return false;
	}else{
		$("#passwdTip").html("");
		return true;
	}
};
function pass2valid(){
	if($("#passwd2").attr("value") != $("#passwd").attr("value")){
		$("#passwd2Tip").html("<span style='color:red;'>两次密码输入不一致!</span>");
		return false;
	}else{
		$("#passwd2Tip").html("");
		return true;
	}
};
</script>
</html>